#!/bin/bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
  SOURCE="$(readlink "$SOURCE")"
  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
SOURCE="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
export SWI_HOME_DIR=$SOURCE/usr/lib/swi-prolog
export TERMINUSDB_SERVER_PACK_DIR=$SOURCE/usr/lib/swi-prolog/pack
export TERMINUSDB_SERVER_INDEX_PATH=$(pwd)/index.html
export TERMINUSDB_SERVER_DB_PATH=$(pwd)/storage
export TERMINUSDB_SERVER_REGISTRY_PATH=$(pwd)/registry.pl
export TERMINUSDB_LOG_PATH=$(pwd)/httpd.log
export TERMINUSDB_SERVER_TMP_PATH=/tmp
export TERMINUSDB_SSL_CERT=$SOURCE/usr/share/terminusdb/localhost.crt
export TERMINUSDB_SSL_CERT_KEY=$SOURCE/usr/share/terminusdb/localhost.key
$SOURCE/usr/bin/swipl -g halt $SOURCE/usr/share/terminusdb/start.pl "$@"
